home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Tools & Apps / Networking & Communications / Serial NB Sample Driver / Task / inc / write.c < prev   
Encoding:
C/C++ Source or Header  |  1991-11-15  |  2.4 KB  |  117 lines  |  [TEXT/MPS ]

  1. /********************************************************************************/
  2. /*                                                                                */
  3. /*        write.c - write request processing.                                        */
  4. /*                                                                                */
  5. /*        Richard W. Mincher.  February 19, 1990.                                    */
  6. /*                                                                                */
  7. /*        Copyright © 1990 Apple Computer, Inc.  All rights reserved.                */
  8. /*                                                                                */
  9. /********************************************************************************/
  10.  
  11. #include    "AROSE.h"
  12. #include    "os.h"
  13. #include    "managers.h"
  14.  
  15. #include    "ARDriver.h"
  16. #include    "ARTask.h"
  17.  
  18. WriteCall()
  19. {
  20. #ifdef    DEBUG
  21.     printf("Write received.  mDataPtr = %x, mDataSize = %x\n",
  22.         msg->mDataPtr, msg->mDataSize );
  23. #endif    DEBUG
  24.  
  25. //    Initialize internal data.
  26.  
  27.     G->writeCmd = 1;
  28.  
  29.     msg->mOData[0] = msg->mDataSize;
  30.     msg->mOData[1] = msg->mDataPtr;
  31.     msg->mNext = 0;
  32.     
  33. //    Place on waiting queue.
  34.  
  35.     if (G->txQHead)
  36.     {
  37.         G->txQTail->mNext = msg;
  38.         G->txQTail = msg;
  39.         return;
  40.     }
  41.     
  42.     G->txQHead = msg;
  43.     G->txQTail = msg;
  44.     TickleWrite();
  45. }
  46.  
  47. TickleWrite()
  48. {
  49.     short            s;
  50.     message            *m;
  51.     tid_type        temp;
  52.     short            count;
  53.  
  54.     if (G->txQHead->mOData[0] == 0)
  55.     {
  56.         m = G->txQHead;
  57.         G->txQHead = G->txQHead->mNext;
  58.         temp = m->mTo;
  59.         m->mTo = m->mFrom;
  60.         m->mFrom = temp;
  61.         m->mCode |= 1;
  62.         Send( m );
  63.     }
  64.  
  65.     if (G->txQHead && (count = G->txMax - G->txCount))
  66.     {        
  67.         if (count > G->txQHead->mOData[0])
  68.             count = G->txQHead->mOData[0];
  69.  
  70.         if (count > (G->txLast - G->txIn))
  71.         {
  72.             NetCopy( G->txQHead->mFrom, (char *)(G->txQHead->mOData[1]),
  73.                     G->txQHead->mTo, G->txIn, G->txLast - G->txIn );
  74.             count -= G->txLast - G->txIn;
  75.             s = Spl(7);
  76.             G->txCount += G->txLast - G->txIn;
  77.             G->sTxCount += G->txLast - G->txIn;
  78.             (void)Spl(s);
  79.             G->txQHead->mOData[0] -= G->txLast - G->txIn;
  80.             G->txQHead->mOData[1] += G->txLast - G->txIn;
  81.             G->txIn = G->txFirst;
  82.         }
  83.         
  84.         NetCopy( G->txQHead->mFrom, (char *)(G->txQHead->mOData[1]),
  85.             G->txQHead->mTo, G->txIn, count);
  86.         s = Spl(7);
  87.         G->txCount += count;
  88.         G->sTxCount += count;
  89.         (void)Spl(s);
  90.         G->txIn += count;
  91.         if (G->txIn == G->txLast)
  92.             G->txIn = G->txFirst;
  93.         G->txQHead->mOData[0] -= count;
  94.         G->txQHead->mOData[1] += count;
  95.                     
  96.     }
  97.     
  98.     s = Spl(7);
  99.     count = G->txCount;
  100.     if (G->txQHead)
  101.     {
  102.         if (count < TICKLESIZE)
  103.             G->txTickle = count;
  104.         else
  105.             G->txTickle = TICKLESIZE;
  106.     }
  107.     else
  108.         G->writeCmd = 0;
  109.     G->txTickle = 0;
  110.     
  111. //    Start Transmitter here if necessary
  112.  
  113.     if (!G->moreTx && G->txCount)
  114.         tbeint();
  115.     (void)Spl(s);
  116. }
  117.